Skip to content

Add BLE Wi-Fi provisioning for combo devices (miiocli ble) - #2102

Open
A4E wants to merge 2 commits into
rytilahti:masterfrom
A4E:ble-provisioning
Open

A4E wants to merge 2 commits into
rytilahti:masterfrom
A4E:ble-provisioning

Conversation

@A4E

@A4E A4E commented Nov 21, 2026

Copy link
Copy Markdown

Newer Xiaomi Wi-Fi devices built on combo modules (Wi-Fi + BLE, e.g. Bouffalo BL602 advertised as
MIBLE_BL602) no longer open a *_miap* access point after a Wi-Fi reset, so Device.configure_wifi()
cannot reach them. The vendor app provisions them over Bluetooth instead. This PR adds that path.

What's added

  • miio/ble_provisioning.py: Xiaomi "standard auth" key exchange (ECDH P-256, HKDF mible-setup-info),
    the framing used on the FE95 service (characteristics 0x0010 / 0x0019), and the encrypted Wi-Fi
    configuration package (TLV: uid, ssid, password, gmt offset, country domain, time zone, config type,
    country code, optional bind key); MiBeacon parsing to find devices in setup mode.
  • miiocli ble scan and miiocli ble provision --ssid ... --uid ... --region ....
  • Optional dependency ble = ["bleak>=0.22"]; bleak is imported lazily, the protocol helpers and the CLI
    import work without it.
  • Docs: a section in discovery.rst.
  • Tests: protocol helpers plus a simulated device that runs the whole flow (no Bluetooth needed).

Tested on hardware
xiaomi.derh.lite (Xiaomi Smart Dehumidifier Lite), BL602, BLE firmware 3.6.5_0581, device firmware
1.0.1, from macOS (CoreBluetooth). Findings, also noted in the docs:

  • the Xiaomi account uid is mandatory: without it the device accepts the package and reports success,
    but never joins the network (a random bind_key does not help);
  • the token is not delivered over BLE and the handshake keeps it hidden, so miiocli cloud list is needed
    afterwards; blocking the device's internet access after that keeps local control working;
  • a non-existent country_domain (e.g. zz) is accepted, the device joins Wi-Fi but never reaches the
    cloud.

Sources
The Wi-Fi step was reconstructed from the device side of the protocol in the com.mijiasdk.bleserver
package of a decompiled Xiaomi speaker launcher (OpenMico/MicoLauncher), cross-checked with dnandha/miauth,
pvvx's TelinkMiFlasher and dentra's miot_cwbs01 PoC, then confirmed on the device above. No code is
copied from these projects. A standalone script with a longer protocol write-up:
https://github.com/A4E/xiaomi-ble-provision

pytest miio/tests/test_ble_provisioning.py: 7 passed; ruff and mypy are clean for the new module.
The 5 failures in chunmi/cooker_multi tests happen on master too (Python 3.14 here).

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.53%. Comparing base (9a00e08) to head (7e15cf8).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2102      +/-   ##
==========================================
+ Coverage   84.31%   84.53%   +0.22%     
==========================================
  Files         201      202       +1     
  Lines       20656    20950     +294     
  Branches     1121     1150      +29     
==========================================
+ Hits        17417    17711     +294     
  Misses       3047     3047              
  Partials      192      192              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant